﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics.Contracts;

namespace RPGMapRevealer
{
    public partial class FileSelectorUserControl : UserControl
    {
        /// <summary>
        /// Constructs a new File Selector control
        /// </summary>
        public FileSelectorUserControl()
        {
            InitializeComponent();
        }

        /// <summary>
        /// The filename the user selected
        /// </summary>
        public String FileName
        {
            get { return textBoxFileName.Text; }
            set { textBoxFileName.Text = value; }
        }

        private String _filter;
        /// <summary>
        /// A filter to use to limit the number of files displayed
        /// </summary>
        public String Filter
        {
            get { return _filter; }
            set { _filter = value; }
        }

        private void buttonOpenFileDialog_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Filter = _filter;
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    textBoxFileName.Text = ofd.FileName;
                }
            }
        }

        [ContractInvariantMethod]
        private void InvariantMethod()
        {
            Contract.Invariant(textBoxFileName != null);
            Contract.Invariant(buttonOpenFileDialog != null);
        }
    }
}
